package model

import (
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
)

var db *gorm.DB

func Connect() {
	var err error
	gorm.DefaultTableNameHandler = func(db *gorm.DB, defaultTableName string) string {
		return "blog_" + defaultTableName
	}
	db, err = gorm.Open("mysql", "root:123123@tcp(127.0.0.1)/blog?charset=utf8&parseTime=True&loc=Local")
	if err != nil {
		Close()
		panic("mysql connect is fault")
	}
}

func Close() {
	defer db.Close()
}
